﻿using MediatR;
using T.Materials.API.Application.Command.MaterialStoreCommand;
using T.Materials.Domain.Model;
using T.Materials.Repository.MaterialsInterface;

namespace T.Materials.API.Application.CommandHandler.MaterialStoreCommandHandler
{
    /// <summary>
    /// 物资与入库添加命令处理器
    /// </summary>
    public class AddMaterialStoreCommandHandler : IRequestHandler<AddMaterialStoreCommand, int>
    {
        /// <summary>
        /// 物资与入库仓储接口
        /// </summary>
        protected readonly IMaterialStoreRepository materialStoreRepository;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="materialStoreRepository">物资与入库仓储接口</param>
        public AddMaterialStoreCommandHandler(IMaterialStoreRepository materialStoreRepository)
        {
            this.materialStoreRepository = materialStoreRepository;
        }

        /// <summary>
        /// 物资与入库添加命令处理器
        /// </summary>
        /// <param name="request">请求</param>
        /// <param name="cancellationToken">取消标记</param>
        /// <returns>返回受影响的行数</returns>
        public async Task<int> Handle(AddMaterialStoreCommand request, CancellationToken cancellationToken)
        {
            return await materialStoreRepository.AddAsync(new MaterialStore() { CompanyID = request.CompanyID, User_Id = request.User_Id, NameOfGoods = request.NameOfGoods, MaterialStoreType = request.MaterialStoreType, Material = request.Material, Specifications = request.Specifications, CountryId = request.CountryId, EconomizeId = request.EconomizeId, Number = request.Number,TotalNumber=request.Number, DeliveryDate = request.DeliveryDate, UsageDescription = request.UsageDescription, Applicant = request.Applicant, ApprovalStatus = request.ApprovalStatus, Approver = request.Approver, Registrant = request.Registrant, PaymentMethod = request.PaymentMethod,OtherPaymentMethods=request.OtherPaymentMethods, UnitPrice = request.UnitPrice, Notes = request.Notes, MaterialClassificat = request.MaterialClassificat, CreatedBy = request.CreatedBy, CreatedDate = DateTime.Now });
        }
    }
}
